<template>
	<l-tab v-model="tabActive" :list="tabList">
		<el-form label-width="130px" :model="info" :rules="rules">
			<el-form-item :label="`${info.type}：`" prop="content">
				<editor v-model="info.content" :height="552" />
			</el-form-item>
			<el-form-item>
				<el-button :loading="loading" class="!w-[107px] !h-[40px]" type="primary" @click="save(info)">保存 </el-button>
			</el-form-item>
		</el-form>
	</l-tab>
</template>
<script>
import Editor from '@/components/Editor';
export default {
	name: 'Text',
	components: {
		Editor,
	},
	data() {
		return {
			tab: [],
			tabList: [],
			tabComponent: ['registered', 'plus'],
			tabActive: 0,
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				type: null,
				title: null,
				content: null,
				tenantId: null,
			},
			loading: false,
			rules: {
				content: [{ required: true, message: '请输入', trigger: 'blur' }],
			},
		};
	},
	computed: {
		info() {
			return this.tab[this.tabActive] || {};
		},
	},
	created() {
		this.getList();
	},
	methods: {
		getList() {
			this.$request.post('/system/text/list', this.queryParams).then((response) => {
				this.tab = response.data.records;
				this.tabList = response.data.records.map((item) => item.type);
			});
		},

		handleTab(index) {
			this.tabActive = index;
		},
		save(value) {
			if (!value.content) {
				this.$message.error('请输入协议内容!');
				return;
			}

			this.$request.post('/system/text/edit', value).then(() => {
				this.msgSuccess('修改成功');
			});
		},
	},
};
</script>

<style lang="scss" scoped>
.message {
	::v-deep .el-card__body {
		height: 100vh;
	}
	::v-deep {
		.ql-toolbar {
			width: 302px;
			border: 1px solid #e5e5e5;
		}
		.editor {
			border: 1px solid #e5e5e5;
			border-top: none;
		}
	}
	&__left {
		border: 1px solid #4c59c6;
		border-radius: 4px;
		&--item {
			cursor: pointer;
			height: 48px;
			color: #2c333f;
			font-size: 12px;
			text-align: center;
			line-height: 48px;
			font-family: Microsoft YaHei-Regular, Microsoft YaHei;
		}
		&--active {
			background: rgba(76, 89, 198, 0.2);
			color: #4c59c6;
			font-weight: bold;
		}
	}
	&__right {
		border-left: 1px solid #f3f4f7;
	}
}
</style>
